--- title: "完全日期" created: 2025-11-28 tags: - 算法 --- # 完全日期 ## 题目 [完全日期](https://www.lanqiao.cn/problems/1562/learning/) ![[image-2536fbd3.png]] ## 思路分析 ![[image-59f42742.png]] ## 代码实现 ```cpp #include using namespace std; #define endl '\n' int days[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; bool is_leap(int y){ return y%100 && y%4==0 || y%400==0; } int get_days(int y,int m){ return days[m]+(m==2 && is_leap(y)); } void next_day(int &y,int &m,int &d){ d++; if(d>get_days(y,m)){ d=1; m++; if(m>12){ m=1; y++; } } } int main() { ios::sync_with_stdio(0),cin.tie(0),cout.tie(0); set pn; for(int i=1;i*i<50;i++){ pn.insert(i*i); } int cnt=0; int cury=2001,curm=1,curd=1; while(cury<2022){ int tempy=cury,tempm=curm,tempd=curd; int sum=0; while(tempy){ sum+=tempy%10; tempy/=10; } while(tempm){ sum+=tempm%10; tempm/=10; } while(tempd){ sum+=tempd%10; tempd/=10; } if(pn.count(sum)) cnt++; next_day(cury,curm,curd); } cout<